package web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.codec.digest.DigestUtils;

import entity.Admin;

import service.AdminService;
import util.web.ServletUtil;

public class AdminLogin extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		AdminService adminService = new AdminService();
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		
		Admin admin = adminService.login(username, DigestUtils.shaHex(password), ServletUtil.getip(request));
		if (admin != null) {
			ServletUtil.setsessionAttri(request, "admin", admin);
			
			
			ServletUtil.sendRedirect(response, "/admin/adminindex.jspx");
		}else {
			ServletUtil.sendRedirect(response, "/admin/loginindex.jspx?state=1001");
		}
	}

	
	
	
	
	
	
}
